package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.baoding.api.bean.BankBind
import client.comm.baoding.api.bean.KTxJl
import client.comm.commlib.network.data.JsonResult
import client.comm.baoding.api.bean.TxJl
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.commlib.network.data.Ret

class TxjlViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)
    val type = MutableLiveData<String>("1")

    val isOneLoading = MutableLiveData<Boolean>(false)
    val isTwoLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val pageTwo = MutableLiveData<Int>(0)

    val callOne = MutableLiveData<JsonResult<TxJl>>()
    val callOneKTx = MutableLiveData<JsonResult<KTxJl>>()
    val callTwoKTx = MutableLiveData<JsonResult<KTxJl>>()

    val cancleCall = MutableLiveData<JsonResult<Ret>>()
    val withdraw_order_pay = MutableLiveData<JsonResult<BankBind>>()

    fun holdOne() {
        if (isOneLoading.value!!)
            return
        hold({
            server.withdraw_record(pageOne.value!!, type.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }


    fun holdOneKTx() {
        if (isOneLoading.value!!)
            return
        hold({
            server.withdraw_tx_record(pageOne.value!!,"2","0")
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOneKTx.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdTwoKTx() {
        if (isTwoLoading.value!!)
            return
        hold({
            server.withdraw_tx_record(pageTwo.value!!,"2","1")
        }, {
            isTwoLoading.value = true
            pageTwo.value = pageTwo.value!! + 1
        }, {
            callTwoKTx.value = it
        }, complete = {
            isTwoLoading.value = false
        })
    }


    fun kt_cancle(id: String) {
        isShowing.value = true
        hold({
            server.withdraw_tx_cancel(id)
        }, success = {
            cancleCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }

    fun withdraw_order_pay(id: String) {
        isShowing.value = true
        hold({
            server.withdraw_order_pay(id)
        }, success = {
            withdraw_order_pay.value = it
        }, complete = {
            isShowing.value = false
        })
    }

}